﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using SharpGIS;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Collections;
using Newtonsoft.Json;
namespace _4SQ
{
    public partial class Venue : PhoneApplicationPage
    {
        string myVenueID;
        string thecode;
        public Venue()
        {
            InitializeComponent();
           GetVenue();


        }

        private void GetVenue()
        {
            string ProviderURI = "https://api.foursquare.com/v2/venues/4b6f8687f964a52053f42ce3?oauth_token=W3O44J0DALQC31JJYSN5SVRJQZ20X2GGNI2LEJDFWX0JC243&v=20120611";
            WebClient webClient = new WebClient();
            webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClientGetVenue_DownloadStringCompleted);
            webClient.DownloadStringAsync(new Uri(ProviderURI));
        }

        void webClientGetVenue_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                
                return;
            }

            JsonSerializer serializer = new JsonSerializer();
            MainVen.RootObject rootObject = (MainVen.RootObject)serializer.Deserialize(new JsonTextReader(new StringReader(e.Result)), typeof(MainVen.RootObject));

           // var tweet = rootObject.results;

            thev.ItemsSource = rootObject.response.venue;
            
            
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //Get Venue Name
           if (this.NavigationContext.QueryString.ContainsKey("VenueID"))
           {
               myVenueID = NavigationContext.QueryString["VenueID"];
           }
           
           thePano.Title = myVenueID;
           thecode = myVenueID;
            
        }
    }
}